//
//  IMPMainTabBarVC.swift
//  MySina
//
//  Created by imppppp on 16/5/19.
//  Copyright © 2016年 IMP. All rights reserved.
//

import UIKit

class IMPMainTabBarVC: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setChildControllers()
        
        let mainTabBar = IMPMainTabBar()
//        self.tabBar = mainTabBar  tabBar 只读的
        setValue(mainTabBar, forKey: "tabBar")
        // 测试,打印tabBar的类型
//        print(tabBar.classForCoder)
    }
    
    // MARK: - 设置子控制器
    private func setChildControllers(){
        
        createChildController(IMPHomeTableVC(), title: "首页", imgName: "tabbar_home")
        createChildController(IMPMessageTableVC(), title: "消息", imgName: "tabbar_message_center")
        createChildController(IMPDiscoverTableVC(), title: "发现", imgName: "tabbar_discover")
        createChildController(IMPProfileTableVC(), title: "我的", imgName: "tabbar_profile")
        
    }
    
    // MARK: - 创建子控制器
    private func createChildController(vc: UIViewController, title: String, imgName: String){
        
        
        
        //        home.navigationItem.title = "首页"
        //        home.tabBarItem.title = "首页"
        // 上面两句的简单写法, 同时设置导航栏和标签按钮的title
        vc.title = title
        // 设置标签按钮的图片, 设置按钮选中状态时的渲染模式
        vc.tabBarItem.image = UIImage(named: imgName)
        vc.tabBarItem.selectedImage = UIImage(named: imgName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        // 按钮文字被选中时的颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        // 同时修改所有标签按钮文字的颜色
        //        tabBar.tintColor = UIColor.orangeColor()
        // 调整标签按钮文字的位置
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
        let nav = IMPNavigationController(rootViewController: vc)
        addChildViewController(nav)
        
    }
    
    

}
